package cz.possoft.explorer.context;

import java.util.List;

/**
 * Immutable class which encapsulate informations about single object.
 * 
 * @author <a href="mailto:mposolda@gmail.com">Marek Posolda</a>
 * @version $Revision$
 */
public class ObjectContext<C,T>
{
   private final C value;
   
   private final Class<? super C> clazz;
   
   private final List<FieldContext<?,T>> fieldContextList;
   
   public ObjectContext(C value, List<FieldContext<?,T>> fieldContextList, Class<? super C> clazz)
   {
      if ((value== null) || (fieldContextList == null) || (clazz == null))
      {
         throw new IllegalArgumentException("Non null object accepted.");
      }
      this.value = value;
      this.fieldContextList = fieldContextList;
      
      // this should be safe if we declare <C> as correct type
      this.clazz = clazz;
   }

   public C getValue()
   {
      return value;
   }

   public Class<? super C> getClazz()
   {
      return clazz;
   }

   public List<FieldContext<?,T>> getFieldContextList()
   {
      return fieldContextList;
   }
   
   public boolean equals(Object o)
   {
      if (!(o instanceof ObjectContext))
      {
         return false;
      }
      ObjectContext<?,?> that = (ObjectContext<?,?>)o;
      return (this.value.equals(that.value) && this.fieldContextList.equals(fieldContextList));
   }
   
   public int hashCode()
   {
      return value.hashCode() * 13 + fieldContextList.hashCode() * 17;
   }
   
}

